home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / OS / ZPointer.h < prev    next >
Text File  |  1997-06-18  |  2KB  |  87 lines

  1. /*
  2.  *  File:        ZPointer.h
  3.  *  Summary:    A class to encapsulate non-relocatable memory.
  4.  *  Written by:    Jesse Jones
  5.  *
  6.  *    Abstract:    TPointer uses reference counting so that when an 
  7.  *                TPointer is copied the old and new objects point to 
  8.  *                the same block of memory. This means that TPointer 
  9.  *                objects can be treated just like regular pointer's. In 
  10.  *                particular, they can be passed by value without allocating 
  11.  *                a new chunk of memory.
  12.  *
  13.  *    Usage:        There are three ways to allocate memory in Raven: operator new, 
  14.  *                THandle, and TPointer. The new operator should be used to 
  15.  *                allocate small amounts of memory that won't change size. 
  16.  *                TMemHandle should be used for large chunks of memory. TPointer 
  17.  *                should be used for large chunks of memory that cannot move.
  18.  *
  19.  *  Copyright ゥ 1996 Jesse Jones. 
  20.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  21.  *
  22.  *  Change History (most recent first):
  23.  *
  24.  *         <->     1/14/96    JDJ        Created.
  25.  */
  26.  
  27. #pragma once
  28.  
  29. #include <ZConstants.h>
  30. #include <ZTypes.h>
  31.  
  32.  
  33. //-----------------------------------
  34. //    Forward References
  35. //
  36. class ZPointerRef;
  37.  
  38.  
  39. // ===================================================================================
  40. //    class TPointer
  41. // ===================================================================================
  42. class TPointer {
  43.  
  44. //-----------------------------------
  45. //    Initialization/Destruction
  46. //
  47. public:
  48.                         ~TPointer();
  49.  
  50.     explicit             TPointer(ulong bytes = 0, bool zeroBytes = kDontZeroBytes);
  51.  
  52.                         TPointer(Ptr takePtr);
  53.  
  54.                         TPointer(const TPointer& rhs);
  55.  
  56.             TPointer&     operator=(const TPointer& rhs);
  57.     
  58. //-----------------------------------
  59. //    New API
  60. //
  61. public:
  62.             const Byte* GetPtr() const;
  63.  
  64.             Byte*         GetPtr();
  65.  
  66.             ulong         GetSize() const;
  67.             
  68.             void         SetSize(ulong bytes, bool zeroBytes = kDontZeroBytes);    
  69.                         // Note that this may invalidate references to the pointer!
  70.  
  71.             void         Detach();
  72.                         // If the letter is being shared this will create a new letter
  73.                         // referenced only by 'this'.
  74.     
  75.             bool        operator==(const TPointer& rhs) const;
  76.  
  77.             bool        operator!=(const TPointer& rhs) const        {return !this->operator==(rhs);}
  78.  
  79. //-----------------------------------
  80. //    Member data
  81. //
  82. private:
  83.     ZPointerRef*    mPointerRef;
  84. };
  85.  
  86.  
  87.